<?php
if(!defined('_SetYour_')) die('Error');# Definicion de seguridad
// CONSULTA
if($_POST['nombre']&&$_POST['apeido']&&$_POST['clave1']){
		if(XSRF("admin-wmb.php")){
			if($Usuarios=$SQL->consulta(
			"UPDATE set_usuarios 
			SET nombre = '".clean($_POST['nombre'])."',
			".(($_POST['clave2']!='******')?"clave = '".sha1($_POST['clave2'])."',":"")."
				apeido = '".clean($_POST['apeido'])."', 
				email = '".clean($_POST['email'])."',
				sexo = '".clean($_POST['sexo'])."',
				imagen = '".clean($_POST['imagen'])."',
				cargo = '".clean($_POST['cargo'])."'
			WHERE id =".$id." LIMIT 1;")){
			echo "<label class='titulo'>$_P[ucorrect2]<br /></label>";
			}else{
			echo "<label class='titulo'>$_P[uerror]<br /></label>";
			}
			?><div  class="marco_est" style="border:dashed 1px #000;" >
             <a href="admin-wmb.php?modulo=usuarios" class="link-n">
<img src="imagenes/regresar.jpg"  border="none"/>
<?=$_P['return']?>
</a></div>
			  <?
		}
	}else{
$Usuario=$SQL->fila(
"SELECT *
FROM set_rangos
RIGHT JOIN set_usuarios ON set_usuarios.cargo = set_rangos.id
WHERE  set_usuarios.id=".$id." LIMIT 1");
$Rangos = $SQL->consulta("SELECT id,label FROM set_rangos");
?>
<script type="text/javascript">
function enviar(){
	form=document.guardar;
	if(form.clave1.value.length>=6){
		if(form.clave1.value==form.clave2.value){
			if(form.usuario.value && form.nombre.value && form.email.value){
				form.submit();
			}else{
				alert("<?=$_P['noconfirm']?>");
			}
		}else{
			alert("<?=$_P['fillall']?>");
		}
	}else{
		alert("<?=$_P['passhort']?>");
	}
}
//->
</script>
<label class='titulo'><?=$_P['edit']." ".$_P['user']?><br /></label>
<div  class="marco_est">
<a href="admin-wmb.php?modulo=usuarios" class="link-n">
<img src="imagenes/regresar.jpg"  border="none"/>
<?=$_P['return']?>
</a>
<table width="260" border="0" cellpadding="0" cellspacing="0" style="background:#CCC;text-align:center; margin-left:75px;">
<form method="post" action="" name="guardar">
<tr class="headers">
    <th  height="28"  style="text-align:right"><?=$_P['user']?> :</th>
    <td>
    <input name="usuario" type="text" value="<?=$Usuario->usuario?>" disabled="disabled" />
    </td>
 </tr>
<tr class="headers">
    <th  height="28"  style="text-align:right"><?=$_P['name']?> :</th>
    <td>
    <input name="nombre" type="text" maxlength="20" value="<?=$Usuario->nombre?>" autocomplete="off" />
    </td>
 </tr>
<tr class="headers">
    <th  height="28"  style="text-align:right"><?=$_P['lastname']?> :</th>
    <td>
    <input name="apeido" type="text" maxlength="20" value="<?=$Usuario->apeido?>" autocomplete="off" />
    </td>
 </tr>
<tr class="headers">
    <th  height="28"  style="text-align:right"><?=$_P['password']?> :</th>
    <td>
    <input name="clave1" type="text" onclick="this.value='';" onblur="if(!this.value)this.value='******';" value="******" />
    </td>
 </tr>
<tr class="headers">
    <th  height="28"  style="text-align:right"><?=$_P['confirm']?> :</th>
    <td>
    <input name="clave2" type="text" onclick="this.value='';" onblur="if(!this.value)this.value='******';" value="******" />
    </td>
 </tr>
<tr class="headers">
    <th  height="28"  style="text-align:right"><?=$_P['email']?> :</th>
    <td>
    <input name="email" type="text" maxlength="50" value="<?=$Usuario->email?>" autocomplete="off" />
    </td>
 </tr>
<tr>
    <th  height="28" colspan="2" style="text-align:center;font-size:12pt; background:#<?=$Usuario->fondo?>;color:#<?=$Usuario->color?>"><?=$Usuario->label?></th>
</tr>
<tr class="headers">
    <th  height="28"  style="text-align:right"><?=$_P['rank']?> :</th>
    <td>
<select name="cargo">
<option value='0'>Sin cargo</option>
<?php
if(!empty($Rangos)){
	$i=0;
	foreach($Rangos as $rango){
		$i++;
		echo "<option value='".$rango->id."'>".$rango->label."</option>";
		if($rango->id==$Usuario->cargo) $rangoa=$i;
	}
}
?>
</select>
    </td>
 </tr>
<tr class="headers">
    <th  height="28"  style="text-align:right"><?=$_P['sex']?> :</th>
    <td>
    <select name="sexo">
		<option value='H' selected="selected"><?=$_P['man']?></option>
        <option value='M'><?=$_P['woman']?></option>
	</select>
    </td>
</tr>
<tr class="headers">
    <th  height="28"  style="text-align:right"><?=$_P['img']?> :</th>
    <td>
    <input name="imagen" type="text" maxlength="1000" value="<?=$Usuario->imagen?>" autocomplete="off" />
    </td>
 </tr>
<tr>
    <td colspan="2">
    <input type="button" onclick="enviar();" value="Guardar" />
    </td>
 </tr>
 
</form>
</table>
</div>
<?
if(isset($rangoa)){
?>
<script language="javascript" type="text/javascript">
	var sex;
	document.guardar.cargo.selectedIndex = <?=$rangoa; ?>;
	if("<?=$Usuario->sexo; ?>"=="H"){sex=0;}else{sex=1;}
	document.guardar.sexo.selectedIndex = sex;
</script>
<? }
}
?>